//
//  MosaiAlertShowManager.m
//  MosaiMail
//
//  Created by SXW on 16/12/14.
//  Copyright © 2016年 sxw. All rights reserved.
//

#import "MosaiAlertShowManager.h"

@implementation MosaiAlertShowManager

+ (MosaiAlertShowManager *)shareManager {
    static MosaiAlertShowManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        manager = [[MosaiAlertShowManager alloc] init];
    });
    return manager;
}

- (void)showMessage:(NSString *)msg okTittle:(NSString *)okTittle cancleTittle:(NSString *)cancleTittle action:(alertAction)alertAction{

    self.alertActionBlock = alertAction;
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:msg preferredStyle:UIAlertControllerStyleAlert];
    // 确定按钮
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:okTittle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (alertAction) {
            self.alertActionBlock(alertAction);
        }
    }];
    // 取消按钮
    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:cancleTittle style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:okAction];
    [alertController addAction:cancleAction];
    
//    [okAction setValue:[UIColor blackColor] forKey:@"titleTextColor"];
//    [cancleAction setValue:RGB16(COLOR_FONT_4A4A4A) forKey:@"titleTextColor"];
    UIApplication *app = [UIApplication sharedApplication];
    [app.keyWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
}

- (void)showMessage:(NSString *)msg title:(NSString *)title action:(alertAction)alertAction{

    self.alertActionBlock = alertAction;
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:msg preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (alertAction) {
            self.alertActionBlock(alertAction);
        }
    }];
    [alertController addAction:okAction];
    UIApplication *app = [UIApplication sharedApplication];
    [app.keyWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
}

@end
